package android.tusnotas.notification;

import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.tusnotas.activities.R;
import android.tusnotas.activities.ShowInstancesActivity;
import android.tusnotas.activities.extras.ShowInstancesActivityExtras;
import android.tusnotas.changes.Change;
import android.tusnotas.changes.NewsChange;

public class NewsNotification extends TusNotasNotification{

	private static Integer id = NotificationIDs.NEW_NEWS_NOTIFICATION;
	
	private Change change = null;

	public NewsNotification(Change change){
		super(R.drawable.tusnotas, change.getBarTitle(), System.currentTimeMillis());
		this.change = change;
		
	}
	
	public void configureNotificacion(Service service){
		
		Context context = service.getApplicationContext();
		
		CharSequence title = change.getTitle();
		CharSequence content = change.getContent();

		Intent notificationIntent = new Intent(service.getApplicationContext(), ShowInstancesActivity.class);
		notificationIntent.putExtra(ShowInstancesActivityExtras.NOTIFIED_INSTANCE, ((NewsChange) change).getInstanceId());
		notificationIntent.putExtra(ShowInstancesActivityExtras.NOTIFIED_COURSE, ((NewsChange) change).getCourseId());
		notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
		PendingIntent contentIntent = PendingIntent.getActivity(service.getApplicationContext(), (int) System.currentTimeMillis(), notificationIntent, 0);
		this.setLatestEventInfo(context, title, content, contentIntent);
		
	}

	@Override
	public Integer getId() {
		return id++;
	}

}
